{% extends "skia_telemetry_base.html" %}

{% block content %}

<center>
{% if info_msg %}<font color="red"><b>{{ info_msg }}</b></font><br/><br/>{% endif %}
<h2>Run Lua Scripts</h2>
<br/>
{% if not is_google_chromium_user %}Must have a google or chromium account to trigger benchmarks (contact rmistry@)<br/><br/>{% endif %}
<form name="luaForm" action="lua_script" method="post">
  Paste your Lua script here:<br/>
  <textarea name="lua_script" cols="80" rows="20" {% if not is_google_chromium_user %}disabled{% endif %}></textarea><br/><br/>
  Paste your optional Lua aggregator script here:<br/>
  (assume consolidated output is in a file called /tmp/lua-output)<br/>
  <textarea name="lua_aggregator" cols="80" rows="20" {% if not is_google_chromium_user %}disabled{% endif %}></textarea><br/><br/>
  SKP Repository:
  <select name="pagesets_type_and_chromium_build">
    {% for pageset_type, chromium_builds in pagesets_to_builds.items %}
      {% for chromium_rev, skia_rev, chromium_rev_date in chromium_builds %}
        <option value="{{ pageset_type }}-{{ chromium_rev }}-{{ skia_rev }}">
          {{ pageset_type }} created with {{ chromium_rev|slice:":7" }}-{{ skia_rev|slice:":7" }} (Chromium rev created on {{ chromium_rev_date}})
        </option>
      {% endfor %}
    {% endfor %}

    {% for pageset_type in pageset_types %}
      <option value="{{ pageset_type }}" {% ifequal pageset_type "Deeplinks" %}disabled{% endifequal %}>{{ pageset_type }}</option>
    {% endfor %}
  </select><br/><br/>
  Enter an optional description:<br/>
  <input type="text" name="description" size="35" {% if not is_google_chromium_user %}disabled{% endif %}><br/><br/>
  <input type="submit" value="Queue Lua Task" {% if not is_google_chromium_user %}disabled{% endif %}>
</form>
<hr/>

  <h2>Your Lua script runs history</h2>
  <br/>

  {% if lua_tasks %}
  <table border="1" cellpadding="5">
    <tr bgcolor="#CCCCFF">
      <td><b>Description</b></td>
      <td><b>Pagesets Type</b></td>
      <td><b>Chromium Build</b></td>
      <td><b>Requested Time</b></td>
      <td><b>Completed Time</b></td>
      <td><b>Lua Script Link</b></td>
      <td><b>Lua Aggregator Link</b></td>
      <td><b>Lua Output Link</b></td>
      <td><b>Delete</b></td>
    </tr>
    {% for task in lua_tasks %}
    <tr {% if not task.completed_time %}bgcolor="#8FDF5F"{% endif %} >
      <td>{{ task.description }}</td>
      <td>{{ task.pagesets_type }}</td>
      <td>
        {% if task.chromium_rev and task.skia_rev %}
          <a href='https://chromium.googlesource.com/chromium/src/+/{{ task.chromium_rev }}'>{{ task.chromium_rev|slice:":7" }}</a>-<a href='https://skia.googlesource.com/skia/+/{{ task.skia_rev }}'>{{ task.skia_rev|slice:":7" }}</a>
        {% else %}
          N/A
        {% endif %}
      </td>
      <td>{{ task.requested_time }}</td>
      <td>
        {% if task.completed_time %}
          {{ task.completed_time }}
        {% else %}
          {% ifequal task.key.id_or_name oldest_pending_task_key %}
            In Progress
          {% else %}
            Waiting in Queue
          {% endifequal %}
        {% endif %}
      </td>
      <td align="center">
        {% if task.lua_script_link %}
          <a href='{{ task.lua_script_link }}' target='_blank'>script</a>
        {% else %}
          {% ifequal task.key.id_or_name oldest_pending_task_key %}
            In Progress
          {% else %}
            Waiting in Queue
          {% endifequal %}
        {% endif %}
      </td>
      <td align="center">
        {% if not task.lua_aggregator %}
          N/A
        {% else %}
          {% if task.lua_aggregator_link %}                                           
            <a href='{{ task.lua_aggregator_link }}' target='_blank'>script</a>       
          {% else %}                                                              
            {% ifequal task.key.id_or_name oldest_pending_task_key %}             
              In Progress                                                         
            {% else %}                                                            
              Waiting in Queue                                                    
            {% endifequal %}                                                      
          {% endif %}                                                             
        {% endif %}
      </td>
      <td align="center">
        {% if task.lua_output_link %}
          <a href='{{ task.lua_output_link }}' target='_blank'>output</a>
        {% else %}
          {% ifequal task.key.id_or_name oldest_pending_task_key %}
            In Progress
          {% else %}
            Waiting in Queue
          {% endifequal %}
        {% endif %}
      </td>
      <td align="center">
        <form action="lua_script" name="delete_lua_task" method="post">
          <input type='hidden' name='delete' value='{{ task.key.id_or_name }}'>
          <input type='submit' value='Delete' {% ifequal task.key.id_or_name oldest_pending_task_key %}disabled{% endifequal %}>
        </form>
      </td>
    </tr>
    {% endfor %}
  </table>
  {% else %}
    No Previous runs yet.
  {% endif %}
  <br/>
  <a href='all_tasks#lua'>View runs of all users</a>
</center>

{% endblock %}
